package com.zfx.service.impl;

import com.zfx.mapper.IWorkPlanMapper;
import com.zfx.pojo.WorkPlan;
import com.zfx.service.IWorkPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @description:
 * @author: zfx
 * @version: 1.0
 * @time: 2020-05-13 20:21
 * <p>
 * 修改历史：
 * 修改日期      修改人员    版本    内容
 * 2020-05-13   zfx       1.0
 */
@Service
public class WorkPlanServiceImpl implements IWorkPlanService {

    @Autowired
    private IWorkPlanMapper workPlanMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int update(List<WorkPlan> workPlanList) {
        workPlanMapper.delete(new WorkPlan(workPlanList.get(0).getLevel1SystemId(),
                workPlanList.get(0).getTypeId()));

        if(workPlanList.get(0).getSite() == -1) {
            return 0;
        }

        int num = 0;
        for ( WorkPlan workPlan: workPlanList) {
            num += workPlanMapper.insert(workPlan);
        }
        return num;
    }

    @Transactional(readOnly = true)
    @Override
    public List<WorkPlan> selectByLevel1SystemIdAndTypeId(WorkPlan workPlan) {
        return workPlanMapper.select(workPlan);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int deleteByTableId(int level1SystemId) {
        WorkPlan workPlan = new WorkPlan();
        workPlan.setLevel1SystemId(level1SystemId);
        return workPlanMapper.delete(workPlan);
    }
}
